package com.smartscreen.schedulemanage.controller;

import com.smartscreen.common.response.ApiResponse;
import com.smartscreen.schedulemanage.dto.CreateExamScheduleRequest;
import com.smartscreen.schedulemanage.entity.ExamSchedule;
import com.smartscreen.schedulemanage.service.ExamScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/schedule")
public class ExamScheduleController {
    
    @Autowired
    private ExamScheduleService examScheduleService;
    
    @PostMapping("/exams")
    public ApiResponse<Map<String, String>> createExamSchedule(
            @RequestBody CreateExamScheduleRequest request) {
        String examId = examScheduleService.createExamSchedule(request);
        Map<String, String> data = new HashMap<>();
        data.put("examId", examId);
        return ApiResponse.created("考试安排发布成功", data);
    }
    
    @GetMapping("/exams")
    public ApiResponse<List<ExamSchedule>> getExamSchedules(
            @RequestParam(required = false) String termId,
            @RequestParam(required = false) String gradeId) {
        List<ExamSchedule> examSchedules = examScheduleService.getExamSchedules(termId, gradeId);
        return ApiResponse.success(examSchedules);
    }
}